<!DOCTYPE HTML>

<html lang="en-US" xmlns="http://www.w3.org/1999/xhtml">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <title>Map</title>

    <link rel="stylesheet" href="<?php echo HSUrl::home() ?>/css/magnific-popup.css">
    <link href="<?php echo HSUrl::home() ?>/css/styles.css" rel="stylesheet" media="all"/>

    <link media="screen" type="text/css"
          href="<?php echo HSUrl::home() ?>/css/mbExtruder.css"
          rel="stylesheet">
    <link media="screen" type="text/css"
          href="<?php echo HSUrl::home() ?>/css/style.css" rel="stylesheet">
    <link media="screen" type="text/css"
          href="<?php echo HSUrl::home() ?>/css/fancybox/jquery.fancybox.css" rel="stylesheet">
    <link media="screen" type="text/css"
          href="<?php echo HSUrl::home() ?>/css/responsive.css" rel="stylesheet">
    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
    <meta content="initial-scale=1.0,width=device-width" name="viewport">

    <?php
    Yii::app()->clientScript->registerCoreScript('jquery');
    ?>
    <script type="text/javascript"
            src="https://maps.googleapis.com/maps/api/js?key=<?php echo Yii::app()->params['API_key'] ?>">
    </script>
    <script type="text/javascript"
            src="<?php echo HSUrl::home() . '/js/hs.core.js' ?>"></script>
    <script type="text/javascript" src="<?php echo HSUrl::home() . '/js/jquery.blockUI.js' ?>"></script>
    <script type="text/javascript" src="<?php echo HSUrl::home() . '/js/mbExtruder.js' ?>"></script>
    <script type="text/javascript" src="<?php echo HSUrl::home() . '/js/jquery.mb.flipText.js' ?>"></script>
    <script type="text/javascript" src="<?php echo HSUrl::home() . '/js/jquery.hoverIntent.min.js' ?>"></script>
    <script type="text/javascript" src="<?php echo HSUrl::home() . '/js/jquery.magnific-popup.min.js' ?>"></script>
    <script type="text/javascript" src="<?php echo HSUrl::home() . '/js/jquery.fancybox.js' ?>"></script>

</head>

<body>
<div style="clear: both"></div>
<div style="width: 100%;height: 100%;">
    <div id="header" style="display: block;">
        <div style="width: 70%;display: inline-block">
            <h2 style="display: inline">
                <a href="<?php echo HSUrl::home() ?>" id="logo">
                    <?php echo Yii::app()->params['site_name'] ?>
                </a>
            </h2>

        </div>

        <div class="menu-main-container" id="navigation">
            <ul class="menu" id="dropmenu">

                <li>
                    <a id="lblGetLocation" href="javascript:void(0)">
                        Lấy vị trí hiện tại
                    </a>
                </li>
                <li>
                    <a href="<?php echo HSUrl::getCreateCompanyUrl() ?>" style="line-height: 60px;">Đăng ký công ty</a>
                </li>
                <li>
                    <a href="<?php echo HSUrl::getCreateAdsUrl() ?>" style="line-height: 60px;">Đăng rao vặt</a>
                </li>
                <!--                <li>-->
                <!--                    <a href="-->
                <?php //echo HSUrl::getContactUrl() ?><!--" style="line-height: 60px;">Contact</a>-->
                <!--                </li>-->

            </ul>
            <select id="selectMenu">
                <?php $selected_page = HSCommon::getCurrentUrl();

                $select_home = false;
                $select_company = false;
                $select_ad = false;
                switch ($selected_page) {
                    case HSUrl::home():
                        $select_home = true;
                        break;
                    case HSUrl::getCreateCompanyUrl():
                        $select_company = true;
                        break;
                    case HSUrl::getCreateAdsUrl():
                        $select_ad = true;
                        break;
                    default:
                        $select_home = true;
                        break;
                };
                ?>
                <option <?php echo $select_home ? "selected ='selected'" : "" ?> value="<?php echo HSUrl::home() ?>">
                    Trang chủ
                </option>
                <option value="Lấy vị trí hiện tại">Lấy vị trí hiện tại</option>
                <option
                    <?php echo $select_company ? "selected ='selected'" : "" ?> value="<?php echo HSUrl::getCreateCompanyUrl() ?>">
                    Đăng ký công ty
                </option>

                <option
                    <?php echo $select_ad ? "selected ='selected'" : "" ?> value="<?php echo HSUrl::getCreateAdsUrl() ?>">
                    Đăng rao vặt
                </option>
                <!--                <option value="--><?php //echo HSUrl::getContactUrl() ?><!--">Contact</option>-->

            </select>
        </div>
        <div id="divSearch" style="width: 100%;padding: 10px;margin: auto; text-align: center">
            <input type="text" name="address" id="txtAddress" style="width: 50%"
                   placeholder="Nhập địa chỉ, tên công ty hoặc số điện thoại cần tìm">

            <a href="javascript:void(0)" id="lblSearch">Tìm</a>
        </div>
        <!--        <div id="divSearchResult">-->
        <!---->
        <!--        </div>-->
        <div class="clear"></div>
    </div>
    <?php echo $content ?>
    <div class="ad-wrapper display-none"></div>
</div>
<div style="clear: both"></div>
<div id="divExtruder" class="{title:'Danh sách công ty'} display-none">
</div>
<div id="extruderDirection" class="{title:'Hướng dẫn đường đi'} display-none ">
    <div id="mb-directions-panel" class="display-none"></div>
</div>

<script type="text/javascript">

    $(document).ready(function () {
        getCurrentLocation();
        HS.baseUrl = "<?php echo HSUrl::home();?>";
        $("#searchToggle").click(function () {
            $("#divSearch").toggle(500);
        });

        function getCurrentLocation() {
            HS.Helpers.unblock();
            if (!navigator.geolocation) {
                alert("Geolocation is not supported by your browser");
                return;
            }

            navigator.geolocation.getCurrentPosition(success, error);
        }

        function success(position) {

            if (directionsDisplay != null) {
                directionsDisplay.setMap(null);
                directionsDisplay = new google.maps.DirectionsRenderer({
                    draggable: false
                });
            }
            HS.Helpers.block();
            var latitude = position.coords.latitude;
            var longitude = position.coords.longitude;

            HS.cur_lat = latitude;
            HS.cur_lng = longitude;

            HS.user_lat = latitude;
            HS.user_lng = longitude;

            var pos = new google.maps.LatLng(position.coords.latitude,
                position.coords.longitude);

            var mapOptions = {
                position: pos,
                map: map
            };
            var map = new google.maps.Map($map_wrapper,
                mapOptions);

            var myloc = new google.maps.Marker({
                clickable: false,
                icon: new google.maps.MarkerImage('//maps.gstatic.com/mapfiles/mobile/mobileimgs2.png',
                    new google.maps.Size(22, 22),
                    new google.maps.Point(0, 18),
                    new google.maps.Point(11, 11)),
                shadow: null,
                zIndex: 999,
                map: map
            });

            myloc.setPosition(pos);

            var $cat_id = $("#ddlCategories").val();
            getNearCompany(latitude, longitude, $cat_id, true, '');

            HS.Helpers.unblock();
        }

        $('#lblGetLocation').click(function () {
            HS.Helpers.block();
            getCurrentLocation();
        });

        $("#selectMenu").change(function () {
            var $val = $(this).val();

            if ($val == 'Lấy vị trí hiện tại') {
                HS.Helpers.block();
                getCurrentLocation();
                return;
            }
            else if ($val == "Tìm địa điểm") {
                $("#divSearch").toggle(500);
            }
            else {
                document.location = $val;
            }
        })
    });

</script>

</body>
</html>
